using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace BookShop
{
	/// <summary>
	/// Strongly-typed collection for the PurchaseApplyDetail class.
	/// </summary>
    [Serializable]
	public partial class PurchaseApplyDetailCollection : ActiveList<PurchaseApplyDetail, PurchaseApplyDetailCollection>
	{	   
		public PurchaseApplyDetailCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>PurchaseApplyDetailCollection</returns>
		public PurchaseApplyDetailCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                PurchaseApplyDetail o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the PurchaseApplyDetail table.
	/// </summary>
	[Serializable]
	public partial class PurchaseApplyDetail : ActiveRecord<PurchaseApplyDetail>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public PurchaseApplyDetail()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public PurchaseApplyDetail(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public PurchaseApplyDetail(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public PurchaseApplyDetail(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("PurchaseApplyDetail", TableType.Table, DataService.GetInstance("BookShop"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "ID";
				colvarId.DataType = DbType.Int32;
				colvarId.MaxLength = 0;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarPurchaseApplyID = new TableSchema.TableColumn(schema);
				colvarPurchaseApplyID.ColumnName = "PurchaseApplyID";
				colvarPurchaseApplyID.DataType = DbType.AnsiStringFixedLength;
				colvarPurchaseApplyID.MaxLength = 20;
				colvarPurchaseApplyID.AutoIncrement = false;
				colvarPurchaseApplyID.IsNullable = true;
				colvarPurchaseApplyID.IsPrimaryKey = false;
				colvarPurchaseApplyID.IsForeignKey = false;
				colvarPurchaseApplyID.IsReadOnly = false;
				colvarPurchaseApplyID.DefaultSetting = @"";
				colvarPurchaseApplyID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPurchaseApplyID);
				
				TableSchema.TableColumn colvarIsbn = new TableSchema.TableColumn(schema);
				colvarIsbn.ColumnName = "ISBN";
				colvarIsbn.DataType = DbType.AnsiStringFixedLength;
				colvarIsbn.MaxLength = 20;
				colvarIsbn.AutoIncrement = false;
				colvarIsbn.IsNullable = true;
				colvarIsbn.IsPrimaryKey = false;
				colvarIsbn.IsForeignKey = false;
				colvarIsbn.IsReadOnly = false;
				colvarIsbn.DefaultSetting = @"";
				colvarIsbn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsbn);
				
				TableSchema.TableColumn colvarSummary = new TableSchema.TableColumn(schema);
				colvarSummary.ColumnName = "Summary";
				colvarSummary.DataType = DbType.AnsiString;
				colvarSummary.MaxLength = 50;
				colvarSummary.AutoIncrement = false;
				colvarSummary.IsNullable = true;
				colvarSummary.IsPrimaryKey = false;
				colvarSummary.IsForeignKey = false;
				colvarSummary.IsReadOnly = false;
				colvarSummary.DefaultSetting = @"";
				colvarSummary.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSummary);
				
				TableSchema.TableColumn colvarQuantity = new TableSchema.TableColumn(schema);
				colvarQuantity.ColumnName = "Quantity";
				colvarQuantity.DataType = DbType.Int32;
				colvarQuantity.MaxLength = 0;
				colvarQuantity.AutoIncrement = false;
				colvarQuantity.IsNullable = true;
				colvarQuantity.IsPrimaryKey = false;
				colvarQuantity.IsForeignKey = false;
				colvarQuantity.IsReadOnly = false;
				colvarQuantity.DefaultSetting = @"";
				colvarQuantity.ForeignKeyTableName = "";
				schema.Columns.Add(colvarQuantity);
				
				TableSchema.TableColumn colvarUnit = new TableSchema.TableColumn(schema);
				colvarUnit.ColumnName = "Unit";
				colvarUnit.DataType = DbType.Int32;
				colvarUnit.MaxLength = 0;
				colvarUnit.AutoIncrement = false;
				colvarUnit.IsNullable = true;
				colvarUnit.IsPrimaryKey = false;
				colvarUnit.IsForeignKey = false;
				colvarUnit.IsReadOnly = false;
				colvarUnit.DefaultSetting = @"";
				colvarUnit.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUnit);
				
				TableSchema.TableColumn colvarPublisherID = new TableSchema.TableColumn(schema);
				colvarPublisherID.ColumnName = "PublisherID";
				colvarPublisherID.DataType = DbType.Int32;
				colvarPublisherID.MaxLength = 0;
				colvarPublisherID.AutoIncrement = false;
				colvarPublisherID.IsNullable = true;
				colvarPublisherID.IsPrimaryKey = false;
				colvarPublisherID.IsForeignKey = false;
				colvarPublisherID.IsReadOnly = false;
				colvarPublisherID.DefaultSetting = @"";
				colvarPublisherID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPublisherID);
				
				TableSchema.TableColumn colvarLatestOrderDate = new TableSchema.TableColumn(schema);
				colvarLatestOrderDate.ColumnName = "LatestOrderDate";
				colvarLatestOrderDate.DataType = DbType.DateTime;
				colvarLatestOrderDate.MaxLength = 0;
				colvarLatestOrderDate.AutoIncrement = false;
				colvarLatestOrderDate.IsNullable = true;
				colvarLatestOrderDate.IsPrimaryKey = false;
				colvarLatestOrderDate.IsForeignKey = false;
				colvarLatestOrderDate.IsReadOnly = false;
				colvarLatestOrderDate.DefaultSetting = @"";
				colvarLatestOrderDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLatestOrderDate);
				
				TableSchema.TableColumn colvarLatestRequiredDate = new TableSchema.TableColumn(schema);
				colvarLatestRequiredDate.ColumnName = "LatestRequiredDate";
				colvarLatestRequiredDate.DataType = DbType.DateTime;
				colvarLatestRequiredDate.MaxLength = 0;
				colvarLatestRequiredDate.AutoIncrement = false;
				colvarLatestRequiredDate.IsNullable = true;
				colvarLatestRequiredDate.IsPrimaryKey = false;
				colvarLatestRequiredDate.IsForeignKey = false;
				colvarLatestRequiredDate.IsReadOnly = false;
				colvarLatestRequiredDate.DefaultSetting = @"";
				colvarLatestRequiredDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLatestRequiredDate);
				
				TableSchema.TableColumn colvarIsProcessed = new TableSchema.TableColumn(schema);
				colvarIsProcessed.ColumnName = "IsProcessed";
				colvarIsProcessed.DataType = DbType.Boolean;
				colvarIsProcessed.MaxLength = 0;
				colvarIsProcessed.AutoIncrement = false;
				colvarIsProcessed.IsNullable = true;
				colvarIsProcessed.IsPrimaryKey = false;
				colvarIsProcessed.IsForeignKey = false;
				colvarIsProcessed.IsReadOnly = false;
				
						colvarIsProcessed.DefaultSetting = @"(0)";
				colvarIsProcessed.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsProcessed);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["BookShop"].AddSchema("PurchaseApplyDetail",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public int Id 
		{
			get { return GetColumnValue<int>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("PurchaseApplyID")]
		[Bindable(true)]
		public string PurchaseApplyID 
		{
			get { return GetColumnValue<string>(Columns.PurchaseApplyID); }
			set { SetColumnValue(Columns.PurchaseApplyID, value); }
		}
		  
		[XmlAttribute("Isbn")]
		[Bindable(true)]
		public string Isbn 
		{
			get { return GetColumnValue<string>(Columns.Isbn); }
			set { SetColumnValue(Columns.Isbn, value); }
		}
		  
		[XmlAttribute("Summary")]
		[Bindable(true)]
		public string Summary 
		{
			get { return GetColumnValue<string>(Columns.Summary); }
			set { SetColumnValue(Columns.Summary, value); }
		}
		  
		[XmlAttribute("Quantity")]
		[Bindable(true)]
		public int? Quantity 
		{
			get { return GetColumnValue<int?>(Columns.Quantity); }
			set { SetColumnValue(Columns.Quantity, value); }
		}
		  
		[XmlAttribute("Unit")]
		[Bindable(true)]
		public int? Unit 
		{
			get { return GetColumnValue<int?>(Columns.Unit); }
			set { SetColumnValue(Columns.Unit, value); }
		}
		  
		[XmlAttribute("PublisherID")]
		[Bindable(true)]
		public int? PublisherID 
		{
			get { return GetColumnValue<int?>(Columns.PublisherID); }
			set { SetColumnValue(Columns.PublisherID, value); }
		}
		  
		[XmlAttribute("LatestOrderDate")]
		[Bindable(true)]
		public DateTime? LatestOrderDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.LatestOrderDate); }
			set { SetColumnValue(Columns.LatestOrderDate, value); }
		}
		  
		[XmlAttribute("LatestRequiredDate")]
		[Bindable(true)]
		public DateTime? LatestRequiredDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.LatestRequiredDate); }
			set { SetColumnValue(Columns.LatestRequiredDate, value); }
		}
		  
		[XmlAttribute("IsProcessed")]
		[Bindable(true)]
		public bool? IsProcessed 
		{
			get { return GetColumnValue<bool?>(Columns.IsProcessed); }
			set { SetColumnValue(Columns.IsProcessed, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varPurchaseApplyID,string varIsbn,string varSummary,int? varQuantity,int? varUnit,int? varPublisherID,DateTime? varLatestOrderDate,DateTime? varLatestRequiredDate,bool? varIsProcessed)
		{
			PurchaseApplyDetail item = new PurchaseApplyDetail();
			
			item.PurchaseApplyID = varPurchaseApplyID;
			
			item.Isbn = varIsbn;
			
			item.Summary = varSummary;
			
			item.Quantity = varQuantity;
			
			item.Unit = varUnit;
			
			item.PublisherID = varPublisherID;
			
			item.LatestOrderDate = varLatestOrderDate;
			
			item.LatestRequiredDate = varLatestRequiredDate;
			
			item.IsProcessed = varIsProcessed;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varId,string varPurchaseApplyID,string varIsbn,string varSummary,int? varQuantity,int? varUnit,int? varPublisherID,DateTime? varLatestOrderDate,DateTime? varLatestRequiredDate,bool? varIsProcessed)
		{
			PurchaseApplyDetail item = new PurchaseApplyDetail();
			
				item.Id = varId;
			
				item.PurchaseApplyID = varPurchaseApplyID;
			
				item.Isbn = varIsbn;
			
				item.Summary = varSummary;
			
				item.Quantity = varQuantity;
			
				item.Unit = varUnit;
			
				item.PublisherID = varPublisherID;
			
				item.LatestOrderDate = varLatestOrderDate;
			
				item.LatestRequiredDate = varLatestRequiredDate;
			
				item.IsProcessed = varIsProcessed;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn PurchaseApplyIDColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn IsbnColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn SummaryColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn QuantityColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn UnitColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn PublisherIDColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn LatestOrderDateColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn LatestRequiredDateColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn IsProcessedColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"ID";
			 public static string PurchaseApplyID = @"PurchaseApplyID";
			 public static string Isbn = @"ISBN";
			 public static string Summary = @"Summary";
			 public static string Quantity = @"Quantity";
			 public static string Unit = @"Unit";
			 public static string PublisherID = @"PublisherID";
			 public static string LatestOrderDate = @"LatestOrderDate";
			 public static string LatestRequiredDate = @"LatestRequiredDate";
			 public static string IsProcessed = @"IsProcessed";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
